/*
* Copyright (c) 2008, Vladimir Gumenuk
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the copyright holder nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

class CGP4File
{
public:
    CGP4File();
    virtual ~CGP4File();

    BOOL Load( LPCSTR lpszFilePath, LPPRESET p );

    static void LoadAllParams( LPCSTR lpszFolder, CGP4File& file, LPPRESET pArray );
    void TraceParams();

private:
    class CGP4Param
    {
    public:
        CGP4Param()
        {
            m_dwID    = 0;
            m_dwPos   = 0;
            m_dwValue = 0;
            m_csName  = _T("");
            m_csText  = _T("");
        }

        CGP4Param( const CGP4Param& par )
        {
            m_dwID    = par.m_dwID;
            m_dwPos   = par.m_dwPos;
            m_dwValue = par.m_dwValue;
            m_csName  = par.m_csName;
            m_csText  = par.m_csText;
        }

        CGP4Param& operator= ( const CGP4Param& par )
        {
            if( this == &par )
                return *this;

            m_dwID    = par.m_dwID;
            m_dwPos   = par.m_dwPos;
            m_dwValue = par.m_dwValue;
            m_csName  = par.m_csName;
            m_csText  = par.m_csText;

            return *this;
        }

        DWORD   m_dwID;
        DWORD   m_dwPos;
        DWORD   m_dwValue;
        CString m_csName;
        CString m_csText;
    };

    typedef vector<CGP4Param> VEC_PARAMS;
    typedef map<DWORD, VEC_PARAMS> MAP_PARAMS;

    MAP_PARAMS m_mapParams;

    HRESULT ProcessGnx4PresetNode( MSXML::IXMLDOMNodePtr& spPresetNode, LPPRESET p );
    HRESULT ProcessParamsNode( MSXML::IXMLDOMNodePtr& spParamsNode, LPPRESET p );
    HRESULT ProcessGenetxNode( MSXML::IXMLDOMNodePtr& spGenetxNode, LPPRESET p );
    HRESULT GetParamValues( MSXML::IXMLDOMNodePtr& spParam, CGP4Param& par );
    void    CopyParamValueToPreset( const CGP4Param& par, LPPRESET p );
    HRESULT ProcessGenetxModel( MSXML::IXMLDOMNodePtr& spGenetxModel, LPPRESET p );
    void    DecompressAmpData( LPBYTE pDst, LPBYTE lpSrc, DWORD dwSrcLen );

    void    DecompressAmpData2( GNX_AMP *pAmp, LPBYTE pSrc, DWORD dwSrcLen );

    void Set_Wham_IPS_Mod_Type( const CGP4Param& par, LPPRESET p );
    void Set_Wham_IPS_Mod_Enable( const CGP4Param& par, LPPRESET p );
    void Set_Delay_Type( const CGP4Param& par, LPPRESET p );
    void Set_Reverb_Type( const CGP4Param& par, LPPRESET p );
    void Set_Stompbox_Type( const CGP4Param& par, LPPRESET p );
    void Set_Amp_Type( const CGP4Param& par, LPPRESET p );
    void Set_Amp_Gain( const CGP4Param& par, LPPRESET p );
    void Set_Amp_Level( const CGP4Param& par, LPPRESET p );
    void Set_Bass_Freq( const CGP4Param& par, LPPRESET p );
    void Set_Bass_Level( const CGP4Param& par, LPPRESET p );
    void Set_Mid_Freq( const CGP4Param& par, LPPRESET p );
    void Set_Mid_Level( const CGP4Param& par, LPPRESET p );
    void Set_Trebe_Freq( const CGP4Param& par, LPPRESET p );
    void Set_Trebe_Level( const CGP4Param& par, LPPRESET p );
    void Set_EQ_Enable( const CGP4Param& par, LPPRESET p );
    void Set_Chan_Presence( const CGP4Param& par, LPPRESET p );
    void Set_Cab_Type( const CGP4Param& par, LPPRESET p );
    void Set_Cab_Tuning( const CGP4Param& par, LPPRESET p );
    void Set_Pedal_Assign( const CGP4Param& par, LPPRESET p );
    void Set_Pedal_MinMax( const CGP4Param& par, LPPRESET p );
    void Set_LFO_Assign( const CGP4Param& par, LPPRESET p );
    void Set_LFO_MinMax( const CGP4Param& par, LPPRESET p );
    void Set_LFO_Speed( const CGP4Param& par, LPPRESET p );
    void Set_LFO_WaveForm( const CGP4Param& par, LPPRESET p );
    void Set_Ctrl_Assign( const CGP4Param& par, LPPRESET p );
    void Set_Ctrl_MinMax( const CGP4Param& par, LPPRESET p );
    void Set_Ctrl_Type( const CGP4Param& par, LPPRESET p );
};
